home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / vb / sqlgrid.exe / SYSPROCS.SQL < prev    next >
Encoding:
Text File  |  1992-02-21  |  3.3 KB  |  114 lines

  1. create procedure sp_vbColCount @Table varchar(30), @Owner varchar(30)
  2. as 
  3.  select count(col.name) 
  4.    from sysobjects obj, syscolumns col, sysusers u 
  5.   where obj.name = @Table
  6.     and u.name = @Owner
  7.     and (obj.uid = u.uid)
  8.     and (obj.id = col.id)
  9.  
  10.  
  11. create procedure sp_vbColDef @Table varchar(30), @Owner varchar(30)
  12. as 
  13.  select substring(col.name,1, 30), col.type, col.length 
  14.    from sysobjects obj, syscolumns col, sysusers u 
  15.   where obj.name = @Table
  16.     and u.name = @Owner
  17.     and (obj.uid = u.uid)
  18.     and (obj.id = col.id)
  19.   order by col.colid
  20.  
  21.  
  22. create procedure sp_vbDBUsers
  23. as 
  24.   select name from sysusers 
  25.    where ((suid != 0) and 
  26.           (suid != -1) and
  27.           (name != 'public'))
  28.  
  29.  
  30. create procedure sp_vbReturnSelectables
  31. as
  32. create table #temp
  33. (
  34. Owner char(30),
  35. TableName char(30),
  36. Type char(2),
  37. id int
  38. )
  39.  
  40. /*  Get tables/views granted select to public or current user  */
  41. insert into #temp
  42.     select user_name(o.uid), o.name, o.type, o.id
  43.         from sysobjects o, sysprotects p
  44.         where p.protecttype = 205 and
  45.               p.action = 193 and
  46.               ( user_name(p.uid) = user_name() or p.uid = 0 ) and
  47.               p.id = o.id and
  48.               o.type IN ('U ','V ','S ')
  49.  
  50. /*  Get tables/views owned by user  */
  51. insert into #temp
  52.     select user_name(o.uid), o.name, o.type, o.id
  53.         from sysobjects o
  54.         where user_name(o.uid) = user_name() and
  55.             o.type IN ('U ','V ','S ')
  56.  
  57. /*  Display the results after dropping revoked tables/views  */
  58. select distinct Owner=rtrim(Owner), TableName=rtrim(TableName), Type
  59.     from #temp
  60.     where id not in (select p.id
  61.                      from sysprotects p
  62.                      where p.protecttype = 206 and
  63.                            p.action = 193 and
  64.                            convert(tinyint,substring(isnull(p.columns,0x1),1,1)) & 0x1 = 0x1 and
  65.                            user_name(p.uid) = user_name() )
  66.     order by 1, 2
  67.  
  68. drop table #temp
  69.  
  70.  
  71. create procedure sp_vbUserSelectables @User varchar(30)
  72. as
  73. create table #temp
  74. (
  75. TableName char(30),
  76. Type char(2),
  77. id int
  78. )
  79.  
  80. /*  Get tables/views granted select to public or current user  */
  81. insert into #temp
  82.     select o.name, o.type, o.id
  83.         from sysobjects o, sysprotects p
  84.         where (p.protecttype = 205) and
  85.               (p.action = 193) and
  86.               ((user_name(p.uid) = user_name()) or 
  87.                (p.uid = 0)) and
  88.               (o.uid = user_id(@User)) and
  89.               (p.id = o.id) and
  90.               (o.type IN ('U ','V ','S '))
  91.  
  92. /*  Get tables/views owned by user  */
  93. if (select user_name()) = @User 
  94. begin
  95.   insert into #temp
  96.     select o.name, o.type, o.id
  97.         from sysobjects o
  98.         where user_name(o.uid) = user_name() and
  99.             o.type IN ('U ','V ','S ')
  100. end
  101.  
  102. /*  Display the results after dropping revoked tables/views  */
  103. select distinct TableName=rtrim(TableName), Type
  104.     from #temp
  105.     where id not in (select p.id
  106.                      from sysprotects p
  107.                      where p.protecttype = 206 and
  108.                            p.action = 193 and
  109.                            convert(tinyint,substring(isnull(p.columns,0x1),1,1)) & 0x1 = 0x1 and
  110.                            user_name(p.uid) = user_name() )
  111.     order by 1, 2
  112.  
  113. drop table #temp
  114.